<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>lesson 30</title>
  <style>
    .area{
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%,-50%);
      width: 300px;
      height: 400px;
      background: #defeab;
    }
    .mask{
      position: absolute;
      top:0;
      right: 0;
      bottom: 0;
      left: 0;
      background: #333;
      opacity: 0.5;
    }
  </style>
  <script src="https://unpkg.com/vue@next"></script>

</head>
<body>
  <div id="root"></div>
</body>
<script>
  // teleport 传送门,可以把组件内的某个布局直接迁移到父组件的某个dom结构下面

  const app = Vue.createApp({
    data() {
      return {
        show: false,
      }
    },
    methods:{
      handleBtnClick(){
        this.show = !this.show;
      }
    },
    template: `
      <div class="area">
        <button @click="handleBtnClick">打开蒙层</button>
        <teleport to="body">
          <div class="mask" v-show="show"></div>
        </teleport>
      </div>
    `
  });

  const vm = app.mount('#root');
</script>
</html>